package net.patterer.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

/**
 * The main application class of Prowon
 */
public class ProwonApplication extends Application {

	/**
	 * Return the name of the application
	 */
	public String getName() {
		return "Prowon";
	}

	/**
	 * Build the actual application screen
	 */
	protected void init() {

		// create the main frame
		JFrame frame = new JFrame(getName());
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				exit();
			}
		});

		createMenuBar(frame);
		
		// create the contents
		
		Dimension minimumSize = new Dimension(100, 50);

		JPanel categoryPanel = new JPanel(new BorderLayout());
		categoryPanel.setMinimumSize(minimumSize);
		JButton button1 = new JButton("Button1");
		categoryPanel.add(button1);
		
		JPanel detailPanel = new JPanel();
		detailPanel.setMinimumSize(minimumSize);
		JButton button2 = new JButton("Button2");
		detailPanel.add(button2);
		
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, categoryPanel, detailPanel);
		splitPane.setOneTouchExpandable(true);
		frame.add(splitPane);
		
		frame.pack();
		frame.setVisible(true);

	}

	/**
	 * Create the menu bar
	 * 
	 * @param frame
	 */
	private void createMenuBar(JFrame frame) {

		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);

		// create the file menu
		JMenu fileMenu = new JMenu("File");
		menuBar.add(fileMenu);

		JMenuItem openMenuItem = new JMenuItem("Open");
		fileMenu.add(openMenuItem);
		fileMenu.addSeparator();
		JMenuItem exitMenuItem = new JMenuItem("Exit");
		fileMenu.add(exitMenuItem);

	}

	/**
	 * Start the application
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		new ProwonApplication().start();
	}

}
